package com.eqxiu.ieditor.api.controller.mall;


import com.eqxiu.ieditor.api.controller.BaseApiController;
import com.eqxiu.ieditor.api.controller.BaseController;
import com.eqxiu.ieditor.commons.web.ResultData;
import com.eqxiu.mall.search.api.IMallSearchServiceApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author suixiangyu
 */
@RestController
@RequestMapping("/api/searchSuggest")
public class SearchSuggestController extends BaseController implements BaseApiController {
    private static final Logger LOGGER = LoggerFactory.getLogger(SearchSuggestController.class);

    @Autowired
    private IMallSearchServiceApi mallSearchServiceApi;

    /**
     * @description 根据输入词查询搜索推荐词
     * @auther suixiangyu
     * @date 2019.3.5
     */
    @PostMapping("/getSuggestListBySearchWord")
    @ResponseBody
    public ResultData getSearchRecommendWord(String searchWord) {
        List<String> suggester = new ArrayList<>();
        try {
            //调用大数据接口，返回搜索建议词
            suggester = mallSearchServiceApi.suggest("99091",searchWord,5);
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
            return success().setList(suggester);
        }
        return success().setList(suggester);
    }
}
